/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entity.function;

/**
 *
 * @author dell
 */
public class Queue 
{
public static class Node
{
//columns_______________________________________________________________________
private Node pnext;
private Object value;
//functions_____________________________________________________________________
     //operator_________________________________________________________________
public Node()
{ 
    
}
public Node(Object value)
{
     this.value=value;
}
     //getter___________________________________________________________________
public Object getValue()
{
     return value;
}
     //setter___________________________________________________________________
public void setValue(Object value) 
{
     this.value = value;
}
     //toString_________________________________________________________________
@Override
public String toString()
{
     return value.toString();
}
}
//columns_______________________________________________________________________    
protected int maxsize;
protected int size;
protected String type;
protected Node phead;
protected Node ptail;
//functions_____________________________________________________________________
     //operator_________________________________________________________________
public Queue()
{
     this.init();
}
public Queue(int maxsize,String type)
{
     this.maxsize=maxsize;
     this.type=type;
     this.init();
}
     //getter___________________________________________________________________
public int getMaxsize() 
{
     return maxsize;
}
public int getSize() 
{
     return size;
}
public String getType() 
{
     return type;
}
public Object getPhead() 
{
        return phead;
}
     //setter___________________________________________________________________
public void setMaxsize(int maxsize) 
{
     this.maxsize = maxsize;
}
public void setSize(int size) 
{
     this.size = size;
}
public void setType(String type) 
{
     this.type = type;
}
     //operator_________________________________________________________________
private void init()
{
     this.phead=this.ptail=new Node();
     this.size=0;
}
public boolean isEmpty()
{
     return this.size<=0||this.phead==this.ptail||this.phead==null;
}
public boolean isFull()
{
     return this.maxsize<=this.size;
}
public void insert(Object value)
{
     if(this.isFull()) this.remove();
     this.ptail.setValue(value);
     this.ptail.pnext=new Node();
     this.ptail=this.phead.pnext;
     this.size++;
}
public void remove()
{
     if(this.isEmpty()) return;
     this.phead=this.phead.pnext;
     this.size--;
}
public Object pop()
{
     Object value=this.phead;
     this.remove();
     return value;
}
     //toString_________________________________________________________________
@Override
public String toString()
{
      String str=maxsize+"\t"+size+"\t"+size+"\t"+type;
      for(Node head=this.phead;head!=null;head=head.pnext) str+="\t"+head;
      return str;
}
}
